import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: () => import("../views/Home"),
    meta: {
      title: "首页"
    }
  },
  {
    path: "/article/:articleId",
    name: "ArticleView",
    component: () => import("../views/ArticleView"),
    meta: {
      title: "文章详情"
    }
  },
  {
    path: "/archive",
    name: "Archive",
    component: () => import("../views/Archive"),
    meta: {
      title: "归档"
    }
  },
  {
    path: "/media",
    name: "Media",
    component: () => import("../views/Media"),
    children: [
      {
        path: "image",
        name: "MediaImage",
        component: () => import("../components/MediaImage")
      },
      {
        path: "music",
        name: "MediaMusic",
        component: () => import("../components/MediaMusic")
      }
    ],
    meta: {
      title: "媒体"
    }
  },
  {
    path: "/leaveComment",
    name: "LeaveComment",
    component: () => import("../views/LeaveComment"),
    meta: {
      title: "留言版"
    }
  },
  {
    path: "/friendLink.js",
    name: "FriendLink",
    component: () => import("../views/FriendLink"),
    meta: {
      title: "友人帐"
    }
  },
  {
    path: "/about",
    name: "About",
    component: () => import("../views/About"),
    meta: {
      title: "关于我"
    }
  }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});

router.beforeEach((to, from, next) => {
  if (to.meta.title) document.title = to.meta.title;
  next();
});

export default router;
